package IOStreamStudy.printStream;

import java.io.IOException;
import java.io.PrintStream;

public class printStreamDemo {
    public static void main(String[] args) throws IOException {
        // System.out的底层是PrintStream
        PrintStream out = System.out;//public final static PrintStream out = null;
        out.println("你好java");
        /* print底层调用的是 write 所以我们可以用write输出
        public void print(String s) {
            if (s == null) {
                s = "null";
            }
            write(s);
        }
        */
        out.write("hello java".getBytes());//print底层调用的是 write 所以我们可以用write输出
        out.close();// 关闭输出流
        //PrintStream中有 public PrintStream(File file)构造器,可以将流输出到文件,
        PrintStream printStream = new PrintStream("D:\\all_projects\\java_projects\\java_ij\\springMVC" +
                "\\NetWork\\src\\cn\\usts\\edu\\IOStreamStudy\\printStream\\a.txt");
        printStream.print("hello java 将流输入到文件中");
        // 修改输出位置,不是标准输出,显示器,而是新的文件
        System.setOut(new PrintStream("D:\\all_projects\\java_projects\\java_ij\\springMVC\\NetWork\\src\\cn\\usts\\edu\\IOStreamStudy\\printStream\\a.txt"));
        System.out.println("父类写入,底层的out已经被修改");
        System.out.println("父类写入,底层的out已经被修改2");
        printStream.close();
    }

}
